<%--
  Created by IntelliJ IDEA.
  User: 郑川东
  Date: 2021/8/4
  Time: 14:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<form class="layui-form" action="" lay-filter="productEdit">
<%--    这里希望在添加用户操作时隐藏，在编辑用户时显示--%>
    <div class="layui-form-item">
        <label class="layui-form-label">仓库名</label>
        <div class="layui-input-block">
            <input type="text" name="depositoryName" lay-verify="depositorynName" autocomplete="off" placeholder="请输入仓库名(只有一个仓库测试仓库1，此项可以不填，将默认添加测试仓库1)" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">产品型号</label>
        <div class="layui-input-block">
            <input type="text" name="modelnum" maxlength="5" lay-verify="modelnum" autocomplete="off" placeholder="请输入产品编号，1xxxx表示IC卡，2xxxx表示机顶盒" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">产品名称</label>
        <div class="layui-input-block">
            <input type="text" name="productName" lay-verify="productName" autocomplete="off" placeholder="请输入产品名称" class="layui-input">
        </div>
    </div>
    <div id="price" class="layui-form-item layui-hide">
        <label class="layui-form-label">价格</label>
        <div class="layui-input-block">
            <input type="text" name="price" lay-verify="price" autocomplete="off" placeholder="请输入价格" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品类型</label>
        <div class="layui-input-block">
            <input type="text" name="goodsType" lay-verify="goodsType" autocomplete="off" placeholder="请输入商品类型（0为IC卡 1为机顶盒）" class="layui-input">
        </div>
    </div>
    <div id="productPurchaser" class="layui-form-item">
        <label class="layui-form-label">订购人/集团</label>
        <div class="layui-input-block">
            <input type="text" name="productPurchaser" lay-verify="productPurchaser" autocomplete="off" placeholder="请输入订购者" class="layui-input">
        </div>
    </div>
    <div id="bussionhallName" class="layui-form-item layui-hide">
        <label class="layui-form-label">营业厅</label>
        <div class="layui-input-block">
            <input type="text" name="bussionhallName" lay-verify="bussionhallName" autocomplete="off" placeholder="请输入营业厅" class="layui-input">
        </div>
    </div>
    <div id="bussionhallArea" class="layui-form-item layui-hide">
        <label class="layui-form-label">营业厅辖区</label>
        <div class="layui-input-block">
            <input type="text" name="bussionhallArea" lay-verify="bussionhallArea" autocomplete="off" placeholder="请输入营业厅辖区" class="layui-input">
        </div>
    </div>
    <div id="note" class="layui-form-item layui-hide">
        <label class="layui-form-label">商品备注</label>
        <div class="layui-input-block">
            <input type="text" name="note" lay-verify="note" autocomplete="off" placeholder="请输入商品备注" class="layui-input">
        </div>
    </div>
    <input type="hidden" id="productId" name="productId" value="${param.productId}" />

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        var $ = layui.$;

        var productId = $("#productId").val() ;
        if (productId != ""){//编辑用户
            document.getElementById("price").className = "layui-form-item";
            document.getElementById("productPurchaser").className = "layui-form-item layui-hide";
            document.getElementById("bussionhallName").className = "layui-form-item";
            document.getElementById("bussionhallArea").className = "layui-form-item";
            document.getElementById("note").className = "layui-form-item";
            $.ajax({
                url:"detailEdit",
                data:"productid=" + productId,
                dataType:"json",
                success:function(data) {
                    form.val('productEdit', data);
                }
            });
        }

        //监听提交
        form.on('submit(formDemo)', function(data){

            layer.msg(JSON.stringify(data.field));
            $.ajax({
                url:"productEdit",
                type:"POST",
                data:data.field,
                success:function (data){
                    if (data.code == 0){
                        table.reload("productManagement");
                        layer.msg(data.msg)
                    }else {
                        layer.msg("操作失败")
                    }
                    layer.closeAll();
                }
            })
            return false;
        });
    });
</script>